import threading

# 创建一个 Event 对象
event = threading.Event()


# 定义一个线程函数，等待事件
def wait_for_event():
    print("Thread A is waiting for the event to be set.")
    event.wait()  # 阻塞，等待事件被设置
    print("Thread A received the event.")


# 定义另一个线程函数，设置事件
def set_event():
    print("Thread B is setting the event.")
    event.set()  # 设置事件
    print("Thread B has set the event.")


# 创建两个线程
threadA = threading.Thread(target=wait_for_event)
threadB = threading.Thread(target=set_event)

# 启动线程
threadA.start()
threadB.start()

# 等待线程执行完成
threadA.join()
threadB.join()

print("Main thread is done.")
